/**
 * @author hotab
 */
(function($) {
	$.fn.makeModalWindow = function(formId, url){
		$('#'+formId).dialog({modal: true,
			open: function(event, ui) {	jQuery('form[name='+formId+']').validationEngine('attach');	console.log(formId);},
			show: 'fade',
			hide: 'fade',
			resizable: false,
			width: 400,
			close: function(event, ui) { jQuery('form[name='+formId+']').validationEngine('hideAll'); },
			buttons: {"Сохранить": function(e){
										if (jQuery('form[name='+formId+']').validationEngine('validate') == true){
											var arr = $('form[name='+formId+']').serializeArray();
											arr.push({name: 'email', value: $('.auth1').text()});
											arr.push({name: 'idfilms', value: $('#addcomment').val()});
											//console.log(arr);
											$.post(url, arr, function(retData, status){
												if (status == "success"){
													$('#tmp').remove();
													$('#body').fillCommentList('commentList', '/films_contr/comment_list', $('#addcomment').val());
												}
											});
											jQuery('form[name='+formId+']').validationEngine('hideAll');
											$('#'+formId).dialog("close");
										}

									}
					}
		});	
	}
})(jQuery);